﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient"  %>
<script runat="server">
    
    protected void Page_Load()
    {
      
       string conStr = @"Data Source=ADMIN-PC\SQLEXPRESS;Initial Catalog=graduate_manage;Integrated Security=True";  
      
      SqlConnection connection = new SqlConnection(conStr);
      SqlCommand cmd = connection.CreateCommand();
      connection.Open();

      cmd.CommandText = " SELECT  COUNT(*)  FROM INFO_GRADUATE";
      SqlDataReader reader = cmd.ExecuteReader();

      reader.Read();
      
      int countEmploy = reader.GetInt32(0); 
      connection.Close();//否则下一步不能重新读

      connection.Open();

      string year= "2011";
    
      cmd.CommandText = "SELECT EMPLOY_SALARY,COUNT(*) AS COUNT_SALARY_EMPLOY " +
      "  FROM EMPLOYINFO_GRADUATE,INFO_GRADUATE" +
      " WHERE EMPLOYINFO_GRADUATE.GRA_ID=INFO_GRADUATE.GRA_ID AND GRA_GRATIME=" + "'" + year + "-06-07'" +
       "GROUP BY EMPLOYINFO_GRADUATE.EMPLOY_SALARY "
       + "ORDER BY EMPLOY_SALARY";
       

     
      reader = cmd.ExecuteReader();
      int [] perc = new int[countEmploy];
      int[] countY = new int[countEmploy];
      string [] salaryX = new string[countEmploy];
      int i=0;
      while (reader.Read())
      {
          salaryX[i] = reader.GetString(0);
          perc[i] = (reader.GetInt32(1) *100)/ countEmploy;
          countY[i] = reader.GetInt32(1); 
          i++;   
      }
      int salary_count = i;
      connection.Close();

      Series series11 = new Series("2011年");
      series11.ChartType = SeriesChartType.Column;
      int j =0;
      for( ; j<i;j++)
      {
          
          series11.Points.AddY(countY[j]);
          series11.Points[j].AxisLabel = salaryX[j];
          series11.Points[j].Label = countY[j].ToString() + '(' + perc[j].ToString() + "%" + ')';
          series11.Points[j].ToolTip =salaryX[j];
      }
      series11.YAxisType = AxisType.Primary;
      series11.YValueType = ChartValueType.Int32;
      Chart1.Series.Add(series11);

      connection.Close();//否则下一步不能重新读
/*
      connection.Open();

      year = "2012";

      cmd.CommandText = "SELECT EMPLOY_SALARY,COUNT(*) AS COUNT_SALARY_EMPLOY " +
      "  FROM EMPLOYINFO_GRADUATE,INFO_GRADUATE" +
      " WHERE EMPLOYINFO_GRADUATE.GRA_ID=INFO_GRADUATE.GRA_ID AND GRA_GRATIME=" + "'" + year + "-06-07'" +
       "GROUP BY EMPLOYINFO_GRADUATE.EMPLOY_SALARY ORDER BY EMPLOY_SALARY";

      reader = cmd.ExecuteReader();

      int[] perc2 = new int[countEmploy];
      int[] countY2 = new int[countEmploy];
      string[] salaryX2= new string[countEmploy];
      i = 0;
      while (reader.Read())
      {
          salaryX[i] = reader.GetString(0);
          perc[i] = (reader.GetInt32(1) * 100) / countEmploy;
          countY[i] = reader.GetInt32(1);
          i++;
      }
      int salary_count2 = i;
      connection.Close(); 
      Series series12 = new Series("2012年");
      series12.ChartType = SeriesChartType.Column;
      j = 0;
      for (; j < i; j++)
      {

          series12.Points.AddXY(salaryX[j], countY[j]);
         // series12.Points[j].AxisLabel = salaryX[j];
          series12.Points[j].Label = countY[j].ToString() + '(' + perc[j].ToString() + "%" + ')';
          series12.Points[j].ToolTip = salaryX[j];
      }
      series12.YAxisType = AxisType.Primary;
      series12.YValueType = ChartValueType.Int32;
      Chart1.Series.Add(series12);
    
*/
    
}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">

    <asp:Chart ID="Chart1" runat="server" Height="350px" Width="500px"

       Palette="Pastel"
      >
        <Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1" BackGradientStyle="DiagonalRight" 
                BackImageTransparentColor="Cyan" BorderColor="Transparent" BorderWidth="0" BackSecondaryColor="Transparent" 
               >
            </asp:ChartArea>
            
                    
        </ChartAreas>
        <Titles>
            <asp:Title  Font="隶书, 12pt" ForeColor="Black" Name="Title1" 
                Text="薪资分布柱状图">
            </asp:Title>
        </Titles>

<BorderSkin SkinStyle="Emboss"></BorderSkin>
    </asp:Chart>


</asp:Content>

